package org.xiha.wiki.apps;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.xiha.wiki.database.AckCatalogView;
import org.xiha.wiki.database.BasicDatabase;
import org.xiha.wiki.domain.AckCatalog;

/**
 * @author summer
 * 
 */
public class ViewAckCatalog {
    public Map<String, Object> showAckCatalogs() {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        List<AckCatalog> rootAckCatalogs = new ArrayList<AckCatalog>();
        
        BasicDatabase db = new BasicDatabase("~/");
        
        db.openAckCatalog();
        AckCatalogView acview = new AckCatalogView(db);
        
        Map<String, AckCatalog> m = acview.getAckCatalogStoredMap();
        
        for (Entry<String, AckCatalog> entry : m.entrySet()) {
            if (entry.getValue().getParentCatalogUniqueNo() == null) {
                rootAckCatalogs.add(entry.getValue());
            }
        }
        
        resultMap.put("rac", rootAckCatalogs);
        resultMap.put("acs", m);
        
        return resultMap;
    }
}
